package 多线程.多线程;

public class ThreadsNB {
    private static final long COUNT = 10_0000_0000;

    public static void main(String[] args) throws Exception {
        serial();
        concurrent();
    }

    private static void serial(){
        long start = System.nanoTime();
        long a = 0;
        for (long i = 0; i < COUNT ;i++) {
            a++;
        }
        long b = 0;
        for (long i = 0; i < COUNT ;i++) {
            b++;
        }
        long end = System.nanoTime();
        double allTime = (end-start) * 1.0 / 1000 / 1000;
        System.out.println("串行执行的时间"+ allTime);
    }

    private static void concurrent() throws Exception{
        long start = System.nanoTime();
        Thread thread = new Thread(() ->{
            long a = 0;
            for (long i = 0; i < COUNT ;i++) {
                a++;
            }
        });
        thread.start();
        long b = 0;
        for (long i = 0; i < COUNT ;i++) {
            b++;
        }
        thread.join();//以上代码全部执行后才会执行下面的代码
        long end = System.nanoTime();
        double allTime = (end-start) * 1.0 / 1000 /1000;
        System.out.println("并发执行的时间"+ allTime);
    }
}
